package com.tiancheng.trade.merchant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author liuzhonghu
 * @date 2024/4/3 16:00
 */
@Getter
@AllArgsConstructor
public enum CostTypeEnum {
    FIXED("1", "固定金额"),
    PERCENTAGE("2", "百分比"),
    ;

    private final String code;
    private final String desc;

    public static String getDescByCode(String code) {
        return Arrays.stream(values()).filter(d -> Objects.equals(d.getCode(), code)).findFirst()
                .map(CostTypeEnum::getDesc).orElse("");
    }

    /**
     * 根据code获取具体枚举，一般switch中使用
     *
     * @param code
     * @return
     */
    public static CostTypeEnum getByCode(String code) {
        return Arrays.stream(values()).filter(d -> Objects.equals(d.getCode(), code)).findFirst().orElse(null);
    }

}
